<template>
  <div>
    <el-dialog append-to-body title="添加合同" :visible.sync="open">
      <el-form ref="form" :model="form" :rules="rules">
        <el-row :gutter="18">
          <el-col :span="12">
            <el-form-item label="客户手机号" prop="phone" >
              <el-input v-model="form.phone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="合同编号" prop="contractNo" >
              <el-input v-model="form.contractNo"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户邮箱" prop="email" >
              <el-input v-model="form.email"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="24">
            <el-form-item prop="fileName" label="上传文件">
              <file-upload ref="fileUpload"
                           :limit="1"
                           :fileSize="5"
                           :fileType="['pdf']"
                           @input="handleInput">

              </file-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click=" open= false">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    import {transformBusiness} from "../../../api/crm/cluetrack";
    import FileUpload from "@/components/FileUpload"
    import {tranfrom} from "@/api/crm/businesstrack"
    export default {
        name: "tranfom",
      props:['bussignId'],
      //引用若以封装的文件上传组件
      components:{FileUpload},
      data(){
          return{
            form:{},
            rules:{
              phone:[{
                required:true,message:'客户手机号不能为空',trigger:'blur'}],
              contractNo:[{required:true,message:'合同编号不能为空',trigger:'blur'}],
              email:[{required:true,message:'客户邮箱不能为空',trigger:'blur'}],
              fileName:[{required:true,message:'合同文件不能为空',trigger:'blur'}]
            },
            open:false,
            id:this.bussignId
          }
      },
      methods:{
        resetForm(){
          this.form={
            id:null,
            phone:null,
            contractNo:null,
            fileName:null,
            email:null
          }
        },
        submitForm(){
          this.$refs.form.validate(valid=>{
            if(valid){
             this.form.id=this.bussignId
              this.form.record='商机转客户'
              tranfrom(this.form).then(resp=>{
                this.$modal.msgSuccess('操作成功');
                this.$emit("success")
                this.open=false
              })
            }
          })
        },
        //自动返回文件名
        handleInput(urls){
          this.form.fileName=urls;
        }
      },
      created() {
      }
    }
</script>

<style scoped>

</style>
